home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992…ugust: Hack to the Future / ADC Developer CD (1992-08) (''Hack To The Future'')_iso / Dev.CD 199208.iso / Technical Documentation / DTS Sample Code / Snippets / OS / ParseFullPathname / ParseFullPathname.p text < prev    next >
Encoding:
Text File  |  1992-07-15  |  2.6 KB  |  107 lines  |  [TEXT/MPS ]

  1. Program ParsePath;
  2.  
  3. uses
  4.     Files,Memory,Errors,IntEnv;
  5.  
  6. const
  7.     noError = 0;
  8.  
  9. type
  10.     longString = record
  11.         length : integer;
  12.         text : Ptr;
  13.     end;
  14.     
  15. var
  16.     theError        : OSErr;
  17.     here            : FSSpec;
  18.     theInputString    : longString;
  19.     tempByte        : Byte;
  20.  
  21.  
  22.  
  23. function GetElement(theElement: StringPtr; thePathname: longString; elementIndex: integer): boolean;
  24. var
  25.     elemStart, elemEnd    : longint;
  26. begin
  27.     elemStart := longint(thePathname.text);
  28.     while (elementIndex > 1) and (elemStart <
  29.                 longint(thePathname.text) + thePathname.length) do begin
  30.         if Ptr(elemStart)^ = ord(':') then
  31.             elementIndex := elementIndex - 1;
  32.         elemStart := elemStart + 1;
  33.     end;
  34.     elemEnd := elemStart;
  35.     while (Ptr(elemEnd)^ <> ord(':')) and (elemEnd <
  36.                 longint(thePathname.text) + thePathname.length) do
  37.         elemEnd := elemEnd + 1;
  38.     if (elemEnd > elemStart) and (elemEnd < elemStart + 32) then begin
  39.         BlockMove(Ptr(elemStart),Ptr(longint(theElement) + 1),elemEnd - elemStart);
  40.         theElement^[0] := char(elemEnd - elemStart);
  41.         GetElement := true;
  42.     end else
  43.         GetElement := false;
  44. end;
  45.  
  46.  
  47. function ParseFullPathName(VAR theResult: FSSpec; thePathname: longString) : OSErr;    { Walk down thePath, returning an FSSpec }
  48.  
  49. var
  50.     theOSError        : OSErr;
  51.     theLevel        : integer;
  52.     theDInfo        : CInfoPBRec;
  53.     theVInfo        : HParamBlockRec;
  54.     
  55. begin
  56.     theLevel := 2;
  57.     ParseFullPathName := noError;
  58.     
  59.     theResult.parID := fsRtDirID;
  60.     
  61.     if GetElement(StringPtr(@theResult.name), thePathname, 1) then begin
  62.         with theVInfo do begin
  63.             ioVRefNum := 0;
  64.             ioNamePtr := Pointer(@theResult.name);
  65.             ioVolIndex := -1;
  66.         end;
  67.         theError := PBHGetVInfo(@theVInfo,false);
  68.         if theError <> 0 then
  69.             ParseFullPathName := theError
  70.         else
  71.             theResult.vRefNum := theVInfo.ioVRefNum;
  72.     end;
  73.     
  74.     while GetElement(StringPtr(@theResult.name), thePathname, theLevel) do begin
  75.         with theDInfo do begin
  76.             ioFDirIndex := 0;
  77.             ioDrDirID := theResult.parID;
  78.             ioVRefNum := theResult.vRefNum;
  79.             ioNamePtr := Pointer(@theResult.name);
  80.         end;
  81.         theError := PBGetCatInfo(@theDInfo, false);
  82.         if theError <> 0 then
  83.             ParseFullPathName := theError
  84.         else
  85.             theResult.parID := theDInfo.ioDrDirID;
  86.         theLevel := theLevel + 1;
  87.     end;
  88. end;
  89.  
  90.  
  91.  
  92. begin    
  93.     if argC <> 2 then writeln('Form: ParseFullPathname <pathname>')
  94.     else begin
  95.         tempByte := Ptr(argV^[1])^;
  96.         theInputString.length := tempByte;
  97.         theInputString.text := Ptr(longint(argV^[1])+1);
  98.         theError := ParseFullPathName(here,theInputString);
  99.         if theError <> noError then
  100.             writeln('Failed on error ',theError,'.')
  101.         else begin
  102.             writeln('  vRefNum: ',here.vRefNum);
  103.             writeln('    DirID: ',here.parID);
  104.             writeln('     Name: ',here.name);
  105.         end;
  106.     end;
  107. end.